<?php


namespace app\phIndex\controller;


use app\phIndex\service\Service;
use app\service\NewsService;

class News extends Service
{
    /**
     * 新闻展示
     * @param $id
     * @throws \Exception
     */
    public function show()
    {
        $id = input('id');
        if(empty($id) || !is_numeric($id)){
            $error = '参数id为数字,且不能为空';
            $this->error = $error;
            return $this->fetch('news:show');
        }
        $res = NewsService::instance()->getNewsById($id);
        if($res['status']) {
            $data = $res['data'];
        }else{
            $data = [];
        }
        $this->news = $data;
        return $this->fetch('news:show');
    }

    /**
     * 公告展示
     * @param $id
     * @throws \Exception
     */
    public function noticeShow()
    {
        $id = input('id'); //1;//input('id');
        if(empty($id) || !is_numeric($id)){
            $error = '参数id为数字,且不能为空';
            $this->error = $error;
            return $this->fetch('news:noticeShow');
        }
        $res = NewsService::instance()->getNoticeById($id);
        if($res['status']) {
            $data = $res['data'];
        }else{
            $data = [];
        }
        $this->notices = $data;
        return $this->fetch('news:noticeShow');
    }

}